package creatnews.service;

import creatnews.utils.Dbutil;

import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * @author 愿得一人心
 * @date 2022/2/25 11:43
 */
public class AddTopicServicImpl implements IAddTopicService{
    @Override
    public void addTopic(String topicname){
            try {
                //获取连接
                Connection conn = Dbutil.getConnection();
                //sql
                String sql = "INSERT INTO news_topic(topicname)"
                        +"values("+"?)";
                //预编译
                //预编译SQL，减少sql执行
                PreparedStatement ptmt = conn.prepareStatement(sql);

                //传参
                ptmt.setString(1, topicname);

                //执行
                ptmt.execute();
        }catch (Exception e){
                e.printStackTrace();
            }

    }


}
